package cn.david.user.contronller;


import cn.david.basic.exception.BusinessExcepiton;
import cn.david.basic.util.AjaxResult;
import cn.david.basic.util.PageList;
import cn.david.org.domain.Shop;
import cn.david.org.query.ShopQuery;
import cn.david.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("")
public class LogininfoController {
    @Autowired
    private IShopService shopService;
    @PostMapping("/settlement")
    public AjaxResult settlement(@RequestBody Shop shop){
        try {
            shopService.settlement(shop);
            return AjaxResult.me();
        } catch (BusinessExcepiton e) {
            return AjaxResult.me().setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("操作失败"+e.getMessage());
        }
    }
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id ){
        try {
            shopService.del(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("删除失败"+e.getMessage());
        }


    }
    @GetMapping("/{id}")
    public Shop queryById(@PathVariable("id") Long id){
        return shopService.getById(id);

    }
    @GetMapping
    public List<Shop> getAll(){
        return shopService.getAll();
    }
    @PostMapping
    public PageList<Shop> list(@RequestBody ShopQuery query){

        return shopService.queryData(query);
    }
    @PatchMapping
    public AjaxResult deleteBys(@RequestBody Long[] ids){
        try {
            shopService.deleteByIds(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("删除失败"+e.getMessage());
        }

    }


}
